package com.wedata.抖音;

import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson2.JSONObject;
import com.doudian.open.api.order_searchList.OrderSearchListRequest;
import com.doudian.open.api.order_searchList.OrderSearchListResponse;
import com.doudian.open.api.order_searchList.param.OrderSearchListParam;
import com.doudian.open.api.token.AccessTokenData;
import com.doudian.open.api.token.AccessTokenResponse;
import com.doudian.open.core.AccessToken;
import com.doudian.open.core.GlobalConfig;
import com.wedata.HttpUtils;

import java.util.UUID;

public class 抖店 {


    public static void main(String[] args) {
        System.out.println(System.currentTimeMillis()/1000);
    }
    public static void main() {
        //设置appKey和appSecret，全局设置一次，本项目不生成Token！
        GlobalConfig.initAppKey("7166066910138730014");
        GlobalConfig.initAppSecret("936896f2-1337-41fe-9288-fca8e4aace98");
        GlobalConfig.AddAppKeyAndAppSecret("7166066910138730014", "936896f2-1337-41fe-9288-fca8e4aace98");
        GlobalConfig.disableSdkLog();

        OrderSearchListRequest request = new OrderSearchListRequest();

        OrderSearchListParam param = new OrderSearchListParam();
        param.setPage(1L);
        param.setSize(10L);
        param.setCreateTimeStart(System.currentTimeMillis()/1000-10*60*60);
        param.setCreateTimeEnd(System.currentTimeMillis()/1000);
        request.setParam(param);
        OrderSearchListResponse response = request.execute(getDouDianToken());
        System.out.println(response);
    }

    public static AccessToken getDouDianToken() {
        cn.hutool.json.JSONObject body = new cn.hutool.json.JSONObject();
        body.put("debug", false);
        body.put("shopNum", 27074918);
        String sign = MD5.create().digestHex(body +"#205dda3a73b49cb6675260e43c1a39e9");
        cn.hutool.json.JSONObject header = new cn.hutool.json.JSONObject();
        header.set("X-SIGN",sign);
        header.set("X-TRACEID", UUID.randomUUID());
        header.set("X-APPKEY", "55753479369");

        cn.hutool.json.JSONObject result = HttpUtils.sendPost("https://wedata.gymcity.com.cn/openapi/third/getDouDianToken", header, body);
        String str = result.getJSONObject("data").getStr("accessToken");
        System.out.println(str);
        AccessTokenResponse tokenResp = new AccessTokenResponse();
        tokenResp.setCode("10000");
        tokenResp.setMsg("success");
        tokenResp.setLogId("202305231548000E04E945ABBE5D00869E");
        AccessTokenData tokenData = new AccessTokenData();
        tokenData.setAccessToken(str);
        tokenData.setExpiresIn(3600L);
        tokenData.setScope("SCOPE");
        tokenData.setShopId("27074918");
        tokenResp.setData(tokenData);
        return AccessToken.wrapWithAppKey(tokenResp, "7166066910138730014");

    }

}



